<?php

declare (strict_types=1);

namespace app\timer\service\bargain;

use app\common\library\helper;
use app\timer\library\Tools;
use app\timer\model\bargain\Task as TaskModel;
use app\common\service\BaseService;

/**
 * 服务类：砍价任务
 * Class Task
 * @package app\timer\service\bargain
 */
class Task extends BaseService
{
    /**
     * 标记已过期的砍价任务
     * @param int $storeId
     * @return bool
     */
    public function overdueEvent(int $storeId): bool
    {
        // 获取已失效的订单ID集
        $model = new TaskModel;
        $endTaskIds = $model->getEndTaskIds($storeId);
        // 记录日志
        Tools::taskLogs('BargainTask', 'overdueEvent', [
            'storeId' => $storeId,
            'endTaskIds' => helper::jsonEncode($endTaskIds)
        ]);
        // 标记订单失效状态
        return empty($endTaskIds) || $model->setIsEnd($endTaskIds);
    }
}